package com.sls.game.dao.enfu.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.enfu.EnfuServerDAO;
import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.enfu.EnfuServerInfo;

/**
 * 
 * @description 恩付商品可充区域对应的服务器--DAO
 * @author Wangxuegang
 * @date 2013-4-28
 */
@Repository("enfuServerDAO")
public class EnfuServerDAOImpl extends SuperDAO<EnfuServerInfo> implements
		EnfuServerDAO {

	/**
	 * 记录查询
	 * 
	 * @param enfuServerInfo
	 * @return
	 */
	@Override
	public String queryGameServer(EnfuServerInfo enfuServerInfo) {
		String hidGameSrv = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuServerMapper.queryGameServer", enfuServerInfo);

		return hidGameSrv;
	}

	/**
	 * 通过goodsId,gameAreaName,gamesrvName查询一条记录
	 * 
	 * @param enfuServerInfo
	 * @return
	 */
	@Override
	public List<EnfuServerInfo> queryOneOrMoreGameServer(
			EnfuServerInfo enfuServerInfo) {
		List<EnfuServerInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.EnfuServerMapper.queryOneOrMoreGameServer",
				enfuServerInfo);

		return list;
	}

	/**
	 * 删除记录
	 * 
	 * @param id
	 */
	@Override
	public void deleteById(String id) {
		this.getSqlSession().delete("mybatis.xml.EnfuServerMapper.deleteById",
				id);
	}

	// =====================================================================
	/**
	 * 根据productid，gameid，areaname，srvname查询记录是否存在
	 * 
	 * @param enfuServerInfo
	 * @return
	 */
	@Override
	public String querySrvInfo(EnfuServerInfo enfuServerInfo) {
		String id = null;
		id = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuServerMapper.querySrvInfo", enfuServerInfo);

		return id;
	}

	/**
	 * 记录插入
	 * 
	 * @param enfuServerInfo
	 */
	@Override
	public void insert(EnfuServerInfo enfuServerInfo) {
		this.getSqlSession().insert("mybatis.xml.EnfuServerMapper.insert",
				enfuServerInfo);
	}

	/**
	 * 记录更新
	 * 
	 * @param enfuServerInfo
	 */
	@Override
	public void updateInfo(EnfuServerInfo enfuServerInfo) {
		this.getSqlSession().update("mybatis.xml.EnfuServerMapper.updateInfo",
				enfuServerInfo);
	}

	/**
	 * 根据gameid和areaname、srvname查询areaid的值
	 * 
	 * @param enfuServerInfo
	 * @return
	 */
	@Override
	public EnfuServerInfo queryEnfuServerInfo(EnfuServerInfo enfuServerInfo) {
		EnfuServerInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuServerMapper.queryEnfuServerInfo",
				enfuServerInfo);
		return info;
	}

	/**
	 * 根据gameid查询游戏服务器表
	 * 
	 * @param productid
	 * @return
	 */
	@Override
	public List<EnfuServerInfo> queryEnfuServerList(String productid) {
		List<EnfuServerInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.EnfuServerMapper.queryEnfuServerList", productid);
		return list;
	}

	/**
	 * 游戏小服，分页查询
	 * 
	 * @param srvInfo
	 * @return
	 */
	@Override
	public Pagination<EnfuServerInfo> queryPaginationList(EnfuServerInfo srvInfo) {
		Pagination<EnfuServerInfo> paginationList = null;
		int rowCount = queryRowCount(srvInfo);
		srvInfo.calculate();
		List<EnfuServerInfo> list = queryResultList(srvInfo);
		paginationList = queryPagination(rowCount, list, srvInfo);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param areaInfo
	 * @return
	 */
	private int queryRowCount(EnfuServerInfo srvInfo) {
		int rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuServerMapper.queryRowCount", srvInfo);
		return rowCount;
	}

	private List<EnfuServerInfo> queryResultList(EnfuServerInfo srvInfo) {
		List<EnfuServerInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.EnfuServerMapper.queryResultList", srvInfo);
		return list;
	}

}
